<?php
	/**
	 * 销量查询
	 * @author QiuXiancCheng
	 * @date 2016-07-13
	 */
	defined('APPLICATION_PATH') or die;
	class Base_SaleController extends Controller_NeedLogin{
		private $departmentModel;
		private $userModel;
		private $salesModel;
		/**
		 * 初始化
		 * {@inheritDoc}
		 * @see Controller_Base::init()
		 */
		public function init() {

			parent::init();
			$this -> departmentModel = new Base_Model_Department;
			$this -> productTypes = new Application_Model_ProductCatalog;
			$this -> userModel = new System_Model_User;
			$this -> salesModel = new Base_Model_Sales;
		}
		public function indexAction() {
			$params = [];
			$params['page'] = !empty($getData['page']) ? $getData['page'] : 1;
			$params['perPage'] = !empty($getData['page_size']) ? $getData['page_size'] : $this->page_size;
			$params['warehouse_code'] = $this->getRequest()->getParam('warehouse_code', '');
			$params['product_type'] = $this->getRequest()->getParam('product_type', '');
			$params['lifecycle'] = $this->getRequest()->getParam('lifecycle', '');
			$params['selected_product_type'] = $this->getRequest()->getParam('selected_product_type', '');
			$params['searchbox'] = $this->getRequest()->getParam('searchbox', '');
			$params['sale_type'] = $this->getRequest()->getParam('sale_type', 'minus_7');
			$params['minus_from'] = $this->getRequest()->getParam('minus_from', '');
			$params['minus_to'] = $this->getRequest()->getParam('minus_to', '');
			$params['dept_id'] = $this->getRequest()->getParam('dept_id', '');
			$params['deval'] = $this -> userModel -> getCategoryParents($params['product_type']);
			$result = $this->salesModel->getSonSaleList($params);
			$depts = $this -> departmentModel -> getDepartment();
			
			$this -> smarty -> assign('data', json_encode($params, true));
			$this->smarty->assign('params', $params);
			$this->smarty->assign('list', $result['list']);
			$this->smarty->assign('page', $this->page($result['count'],$params['perPage']));
			$this->smarty->assign('depts', $this -> departmentModel -> gertDepartmentHTML($depts));
			
			$this -> smarty -> display('base_sales_index.php');
		}

		/**
		 * 总仓销量查询
		 */
		public function sumAction(){
			$params = [];
			$params['page'] = !empty($getData['page']) ? $getData['page'] : 1;
			$params['perPage'] = !empty($getData['page_size']) ? $getData['page_size'] : $this->page_size;
			$params['product_type'] = $this->getRequest()->getParam('product_type', '');
			$params['selected_product_type'] = $this->getRequest()->getParam('selected_product_type', '');
			$params['searchbox'] = $this->getRequest()->getParam('searchbox', '');
			$params['deval'] = $this -> userModel -> getCategoryParents($params['product_type']);
			
			$result = $this->salesModel->getSumSaleList($params);
			
			$this->smarty->assign('params', $params);
			$this->smarty->assign('list', $result['list']);
			$this->smarty->assign('data', json_encode($params, true));
			$this->smarty->assign('page', $this->page($result['count'], $params['perPage']));
			
			$this -> smarty -> display('base_sales_sum.php');
		}
	}